package com.hospital.frontdesk.fronxiang.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.hospital.frontdesk.fronxiang.entity.Consumeinfos;
import com.hospital.frontdesk.fronxiang.service.ConsumeinfosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @description：
 * @author：xyj
 * @date：2021/9/17 14:35
 * @versions：v1.0
 */
@Controller
@RequestMapping("/Consume")
public class ConsumeinfosController {

    @Autowired
    private ConsumeinfosService consumeinfosService;

    @RequestMapping("/pageconsume")
    public String pageconsume(@RequestParam(value = "name", defaultValue = "") String name, @RequestParam(value = "curr", defaultValue = "1") Integer curr, @RequestParam(defaultValue = "5") Integer pageSize, Model model) {
        List<Consumeinfos> pageconsume = consumeinfosService.pageconsume(name, curr, pageSize);
        PageInfo<Consumeinfos> page = new PageInfo<>(pageconsume);
        model.addAttribute("page", page);
        model.addAttribute("name", name);
        return "frontdesk/paythefees";
    }

    @RequestMapping("/index")
    public String home() {
        return "frontdesk/reception";
    }

    @RequestMapping("/transfer")
    @ResponseBody
    public String transfer(String xiangxi, Integer patientId) {
        boolean transfer = consumeinfosService.transfer(xiangxi, patientId);
        return JSON.toJSONString(transfer);
    }

}
